package com.kits.store.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class DbFactory {

    private DbFactory(){

    }
    private static class SingletonHolder{
        private final static DbFactory instance=new DbFactory();
    }
    public static DbFactory getInstance(){
        return DbFactory.SingletonHolder.instance;
    }
    private DaoMaster.DevOpenHelper mHelper;

    private SQLiteDatabase db;
    /**
     * DaoMaster
     */
    private DaoMaster mDaoMaster;
    /**
     * DaoSession
     */
    private DaoSession mDaoSession;
    private Context context;


    public void init(Context context){
        this.context = context;
        mHelper = new DaoMaster.DevOpenHelper(context,"test.db", null);
        mDaoMaster =new DaoMaster(getWritableDatabase());
        mDaoSession = mDaoMaster.newSession();
        FileBeanHelper.getInstance().init(mDaoSession);

    }

    public SQLiteDatabase getWritableDatabase(){
        if(mHelper == null){
            mHelper =new DaoMaster.DevOpenHelper(context,"test.db",null);
        }
        SQLiteDatabase db = mHelper.getWritableDatabase();
        return db;
    }
}
